﻿/*
 * @author: wizardc
 */

using UnityEngine;

namespace Dou.Download
{
    /// <summary>
    /// 下载请求对象
    /// </summary>
    public class DownloadRequest : CustomYieldInstruction
    {
        private DownloadRequestInfo _info;

        internal DownloadRequest(DownloadRequestInfo info)
        {
            _info = info;
        }

        public override bool keepWaiting => isDone;

        /// <summary>
        /// 异步操作是否已经完成
        /// </summary>
        public bool isDone => _info.state == DownloadState.Idle || _info.state == DownloadState.Downloading;

        /// <summary>
        /// 当前下载状态
        /// </summary>
        public DownloadState state => _info.state;

        /// <summary>
        /// 当前下载字节数
        /// </summary>
        public long currentBytes => _info.currentBytes;

        /// <summary>
        /// 下载总字节数
        /// </summary>
        public long totalBytes => _info.totalBytes;

        /// <summary>
        /// 错误码
        /// </summary>
        public DownloadErrorCode errorCode => _info.errorCode;

        /// <summary>
        /// 错误信息
        /// </summary>
        public string errorMsg => _info.errorMsg;
    }

    /// <summary>
    /// 用来给协程传递信息的对象
    /// </summary>
    internal class DownloadRequestInfo
    {
        public DownloadState state;
        public long currentBytes;
        public long totalBytes;
        public DownloadErrorCode errorCode;
        public string errorMsg;
    }
}
